package com.myProject.serves.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myProject.bean.TArea;
import com.myProject.bean.TMeet;
import com.myProject.dao.MeetDao;
import com.myProject.serves.MeetSev;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class MeetSevImpl implements MeetSev {
    @Override
    public List<TMeet> getAllMeetList(TMeet tMeet) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MeetDao md = sqlSession.getMapper(MeetDao.class);
        List<TMeet> list = md.getAllMeetList(tMeet);
        sqlSession.clearCache();
        return list;
    }

    @Override
    public List<TMeet> getOneMeetList(TMeet tMeet) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MeetDao md = sqlSession.getMapper(MeetDao.class);
        List<TMeet> list = md.getOneMeetList(tMeet);
        sqlSession.clearCache();
        return list;
    }

    @Override
    public boolean addMeet(TMeet tMeet) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MeetDao md = sqlSession.getMapper(MeetDao.class);
        int x = md.addMeet(tMeet);
        SqlSessionUtil.commit();
        sqlSession.close();
        return x>0?true:false;
    }

    @Override
    public PageInfo<TMeet> getMeetPage(int pageNo, int pageSize, TMeet tMeet) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MeetDao md = sqlSession.getMapper(MeetDao.class);
        PageHelper.startPage(pageNo,pageSize);
        List<TMeet>list = md.getAllMeetList(tMeet);
        PageInfo<TMeet>page = new PageInfo<TMeet>(list);
        SqlSessionUtil.commit();
//      sqlSession.close();
        return page;
    }

    @Override
    public PageInfo<TMeet> getOneMeetPage(int pageNo, int pageSize, TMeet tMeet) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MeetDao md = sqlSession.getMapper(MeetDao.class);
        PageHelper.startPage(pageNo, pageSize);
        List<TMeet> list = md.getOneMeetList(tMeet);
        PageInfo<TMeet> page = new PageInfo<TMeet>(list);
        SqlSessionUtil.commit();
//      sqlSession.close();
        return page;
    }
}
